package com.fangmao.jetpack.fragment;


import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.fangmao.jetpack.viewmodel.HomeViewModel;
import com.fangmao.jetpack.R;
import com.fangmao.jetpack.databinding.FragmentDetailBinding;

import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.SavedStateViewModelFactory;
import androidx.lifecycle.ViewModelProviders;
import androidx.navigation.Navigation;

/**
 * A simple {@link Fragment} subclass.
 */
public class DetailFragment extends Fragment {


    public DetailFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        HomeViewModel homeViewModel;
        homeViewModel = ViewModelProviders.of(this, new SavedStateViewModelFactory(getActivity().getApplication(), this)).get(HomeViewModel.class);
        FragmentDetailBinding detailBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_detail, container, false);

        detailBinding.setData(homeViewModel);
        detailBinding.setLifecycleOwner(getActivity());
        detailBinding.back.setOnClickListener(Navigation.createNavigateOnClickListener(R.id.action_detailFragment_to_homeFragment));

        return detailBinding.getRoot();
    }
}
